﻿using Modules.System.Attachment;
using PetaPoco;
using PmSoft;
using PmSoft.Caching;
using System.ComponentModel;
using static Modules.Person.PersonConstants;

namespace Modules
{
    /// <summary>
    /// 人员附件表
    ///</summary>
    [TableName("person_attachment")]
    [Description("人员附件表")]
    [PrimaryKey("id", AutoIncrement = false)]
    [CacheSetting(true)]
    [Serializable]
    public class PersonAttachment : IDelEntity, IAttachmentRelationship
    {
        /// <summary>
        ///
        ///</summary>
        [Column("id")]
        public string Id { get; set; }

        /// <summary>
        /// 附件Id
        ///</summary>
        [Column("attachment_id")]
        public string AttachmentId { get; set; }

        /// <summary>
        /// 租户
        ///</summary>
        [Column("tenant")]
        public 人员附件租户 Tenant { get; set; }

        /// <summary>
        /// 主表id
        ///</summary>
        [Column("object_id")]
        public object ObjectId { get; set; }

        /// <summary>
        /// 附件类型
        ///</summary>
        [Column("attachment_type")]
        public 人员附件类型 AttachmentType { get; set; }

        /// <summary>
        /// 修改时间
        ///</summary>
        [Column("create_time")]
        public DateTime CreateTime { get; set; } = DateTime.Now;
        /// <summary>
        /// 是否已删除
        /// 默认值: b'0'
        ///</summary>
        [Column("is_deleted")]
        public bool IsDeleted { get; set; }
        [Ignore]
        string IAttachmentRelationship.BucketName => "person";

        [Ignore]
        string IAttachmentRelationship.Directory => Tenant.GetDescription() + "/" + ObjectId.ToString();

        [Ignore]
        string IAttachmentRelationship.AttachmentId => AttachmentId;
        [Ignore]
        bool IDelEntity.IsDeletedInDatabase { get => IsDeleted; set => IsDeleted = value; }
        #region IEntity 成员

        [Ignore]
        object IEntity.EntityId { get { return this.Id; } }

        #endregion IEntity 成员
    }
}